package demo.practice.linklist;

import demo.practice.ListNode;

public class Offer22 {


    public ListNode getKthFromEnd(ListNode head, int k) {


        if (head == null)
            return null;

        ListNode cur = head;


        while (cur != null && k > 0) {
            cur = cur.next;
            k--;
        }

        ListNode cur2 = head;
        while (cur != null) {
            cur = cur.next;
            cur2 = cur2.next;
        }

        return cur2;
    }

}
